<script setup lang="ts">
import { RouterLink, RouterView, useRoute, useRouter } from 'vue-router'
import HelloWorld from '../components/HelloWorld.vue'
import { useCounterStore } from '@/stores/counter'
import {
  Document,
  Menu,
  Location,
  Setting,
  User as UserIcon,
  Avatar,
  UserFilled,
  CopyDocument,
  Tools,
  HelpFilled,
  StarFilled,
  ArrowLeft,
  ArrowRight,
  ArrowDown
} from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox, ElDropdown, ElDropdownMenu, ElDropdownItem } from 'element-plus'
import { ref } from 'vue'
const route = useRoute();
const router = useRouter();
const user = useCounterStore()

// 侧边栏折叠状态
const collapsed = ref(false)
const toggleCollapse = () => {
  collapsed.value = !collapsed.value
}

const go=()=>{
  router.push("/");
}
</script>

<template>
  <div class="app-container">
    <el-container >
      <!-- 顶部导航栏 -->
      <el-header class="app-header">
        <div class="header-left">
          <el-button 
              type="text" 
              class="menu-toggle-btn"
              @click="toggleCollapse"
              :title="collapsed ? '展开菜单' : '收起菜单'"
            >
              <el-icon v-if="collapsed"><ArrowRight /></el-icon>
              <el-icon v-else><ArrowLeft /></el-icon>
            </el-button>
          <div class="logo-container">
            <el-icon class="logo-icon"><div class="title-icon">🐰</div></el-icon>
            <h1 class="logo-text">溯源管理系统</h1>
          </div>
        </div>
        
        <div class="header-right">
            <div class="user-info" @click.stop>
              <el-avatar class="user-avatar">
                <UserFilled class="user-avatar-icon" />
              </el-avatar>
              <!-- <span class="user-name">{{ user.current.userNickName}}</span>
              <span class="user-name">{{ user.current.userName }}</span> -->
              
            </div>
                <span>个人信息</span>
                <span>系统设置</span>
                <span @click="go()">退出登录</span>
        </div>
      </el-header>
      
      <el-container style="height: 800px;">
        <!-- 侧边栏菜单 -->
        <el-aside 
          :width="collapsed ? '64px' : '240px'" 
          class="app-sidebar"
          :class="{ 'sidebar-collapsed': collapsed }"
          style="height: 800px;"
        >
          <el-menu
            active-text-color="#1890ff"
            background-color="#001529"
            text-color="rgba(255, 255, 255, 0.65)"
            :default-active="route.path"
            router
            class="sidebar-menu"
            :collapse="collapsed"
            :collapse-transition="false"
          >
            <!-- RBAC模块 -->
            <el-sub-menu index="1" >
              <template #title>
                <el-icon><Menu /></el-icon>
                <span>RBAC</span>
              </template>
              
              <el-sub-menu index="1-1">
                <template #title>
                  <el-icon><HelpFilled /></el-icon>
                  <span>权限管理</span>
                </template>
                <el-menu-item index="/AddPermission">
                  <el-icon><StarFilled /></el-icon>
                  <span>添加权限</span>
                </el-menu-item>
                <el-menu-item index="/PermissionView">
                  <el-icon><StarFilled /></el-icon>
                  <span>权限列表</span>
                </el-menu-item>
              </el-sub-menu>

              <el-sub-menu index="1-2">
                <template #title>
                  <el-icon><Menu /></el-icon>
                  <span>角色管理</span>
                </template>
                <el-menu-item index="/AddRole">
                  <el-icon><StarFilled /></el-icon>
                  <span>添加角色</span>
                </el-menu-item>
                <el-menu-item index="/RoleView">
                  <el-icon><StarFilled /></el-icon>
                  <span>角色列表</span>
                </el-menu-item>
              </el-sub-menu>

              <el-sub-menu index="1-3">
                <template #title>
                  <el-icon><Avatar /></el-icon>
                  <span>用户管理</span>
                </template>
                <el-menu-item index="/AddUser">
                  <el-icon><UserIcon /></el-icon>
                  <span>添加用户</span>
                </el-menu-item>
                <el-menu-item index="/UserView">
                  <el-icon><UserIcon /></el-icon>
                  <span>用户列表</span>
                </el-menu-item>
              </el-sub-menu>
            </el-sub-menu>

            <!-- 溯源管理模块 -->
            <el-sub-menu index="2" >
              <template #title>
                <el-icon><Tools /></el-icon>
                <span>溯源管理</span>
              </template>
              <el-menu-item index="/Goods" >
                <el-icon><CopyDocument /></el-icon>
                <span>溯源列表</span>
              </el-menu-item>
              <!-- <el-menu-item index="/Fail" >
                <el-icon><CopyDocument /></el-icon>
                <span>溯源详情</span>
              </el-menu-item>
               <el-menu-item index="/Domain" >
                <el-icon><CopyDocument /></el-icon>
                <span>溯源测试</span>
              </el-menu-item> -->
            </el-sub-menu>
          </el-menu>
        </el-aside>
        
        <!-- 主内容区域 -->
        <el-main class="app-main">
          <RouterView />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<style scoped>
/* 全局重置和基础样式 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* 主容器 */
.app-container {
  width: 100%;
  height: 800px;
  overflow: hidden;
}

/* 顶部导航栏 */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 64px;
  padding: 0 20px;
  background: linear-gradient(135deg, #5062b1 0%, #7d5aa0 100%);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 10;
  transition: all 0.3s ease;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.menu-toggle-btn {
  color: #fff;
  font-size: 18px;
  transition: all 0.3s ease;
}

.menu-toggle-btn:hover {
  transform: rotate(90deg);
  background-color: rgba(101, 46, 46, 0.1);
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 24px;
  color: #fff;
}

.logo-text {
  font-size: 20px;
  font-weight: 600;
  color: #fff;
  margin: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.user-dropdown {
  cursor: pointer;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  transition: background-color 0.3s ease;
}

.user-info:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.user-avatar {
  width: 36px;
  height: 36px;
  background-color: rgba(255, 255, 255, 0.2);
  transition: all 0.3s ease;
}

.user-avatar:hover {
  transform: scale(1.1);
  background-color: rgba(255, 255, 255, 0.3);
}

.user-avatar-icon {
  font-size: 20px;
}

.user-name {
  color: #fff;
  font-size: 14px;
  font-weight: 500;
}

.dropdown-arrow {
  color: #fff;
  font-size: 12px;
  transition: transform 0.3s ease;
}

/* 侧边栏 */
.app-sidebar {
  background-color: #26649e;
  transition: all 0.3s ease;
  box-shadow: 2px 0 8px rgba(137, 68, 68, 0.1);
  overflow: hidden;
}

.sidebar-menu {
  height: 400vh;
  border-right: none;
}

/* 侧边栏折叠状态 */
.sidebar-collapsed .el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 64px;
}

.sidebar-collapsed .el-menu-item-group__title,
.sidebar-collapsed .el-sub-menu__title span,
.sidebar-collapsed .el-menu-item span {
  display: none;
}

/* 菜单项样式优化 */
.el-menu-item,
.el-sub-menu__title {
  transition: all 0.3s ease;
  border-radius: 4px;
  margin: 0 8px;
  height: 40px;
  line-height: 40px;
}

.el-menu-item:hover,
.el-sub-menu__title:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.el-menu-item.is-active {
  background-color: rgba(24, 144, 255, 0.2);
}

/* 主内容区 */
.app-main {
  padding: 24px;
  background-color: #f0f2f5;
  overflow-y: auto;
  transition: all 0.3s ease;
}

/* 自定义滚动条 */
.app-main::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

.app-main::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.app-main::-webkit-scrollbar-thumb {
  background: #c0c4cc;
  border-radius: 4px;
}

.app-main::-webkit-scrollbar-thumb:hover {
  background: #909399;
}

/* 下拉菜单样式 */
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dropdown-item-icon {
  font-size: 14px;
}

.danger-item {
  color: #f56c6c;
}

/* 动画效果 */
.el-avatar,
.el-button,
.el-menu-item,
.el-sub-menu__title {
  transition: all 0.3s ease;
}

/* 响应式设计 */
@media screen and (max-width: 1024px) {
  .app-sidebar {
    width: 64px !important;
  }
  
  .app-sidebar .el-menu--vertical:not(.el-menu--collapse) {
    width: 64px;
  }
  
  .app-sidebar .el-menu-item span,
  .app-sidebar .el-sub-menu__title span {
    display: none;
  }
}

@media screen and (max-width: 768px) {
  .logo-text {
    font-size: 16px;
  }
  
  .app-main {
    padding: 16px;
  }
  
  .app-header {
    padding: 0 12px;
  }
}

/* 淡入动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

  .title-icon {
      font-size: 1.5rem;
  }
  .title-icon {
    font-size: 2rem;
    /* margin-bottom: 8px; */
    display: block;
    animation: logoFloat 2s ease-in-out infinite;
}

@keyframes logoFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
</style>
